package sevensoft.gz031.demos.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sevensoft.gz031.demos.web.entity.CarbonEmission;
import sevensoft.gz031.demos.web.mapper.CarbonEmissionMapper;
import sevensoft.gz031.demos.web.service.CarbonEmissionService;


/**
 * 双碳配置—固定碳排放(业务层)
 */
@Service
public class CarbonEmissionServiceImpl extends ServiceImpl<CarbonEmissionMapper, CarbonEmission> implements CarbonEmissionService {
    @Autowired
    CarbonEmissionMapper carbonEmissionMapper;

    public Integer add(CarbonEmission carbonEmission){
        return carbonEmissionMapper.insert(carbonEmission);
    }

    public Integer update(CarbonEmission carbonEmission){
        return carbonEmissionMapper.updateById(carbonEmission);
    }

    public Integer remove(CarbonEmission carbonEmission){
        LambdaQueryWrapper<CarbonEmission> lqw=new LambdaQueryWrapper<>();
        lqw.eq(CarbonEmission::getId,carbonEmission.getId());
        return carbonEmissionMapper.delete(lqw);
    }

    public IPage<CarbonEmission> selectByPage(Integer page, Integer count){
        IPage<CarbonEmission> iPage=new Page<>(page,count);
        carbonEmissionMapper.selectPage(iPage,null);
        return iPage;
    }

    @Override
    public IPage<CarbonEmission> selectByFuzzy(Integer page, Integer count, CarbonEmission carbonEmission) {
        IPage<CarbonEmission> iPage=new Page<>(page,count);
        //模糊条件
        LambdaQueryWrapper<CarbonEmission> lqw=new LambdaQueryWrapper<>();
        lqw.like(CarbonEmission::getEnergyConsumptionItem,carbonEmission.getEnergyConsumptionItem())
        .or().like(CarbonEmission::getProjectType,carbonEmission.getProjectType())
        .or().like(CarbonEmission::getTimeType,carbonEmission.getTimeType());
        carbonEmissionMapper.selectPage(iPage,lqw);
        return iPage;
    }
}
